<template>
  <a-modal
    :confirmLoading="confirmLoading"
    :disableSubmit="true"
    :title="title"
    :visible="visible"
    :width="width"
    destroyOnClose
    @cancel="handleCancel"
  >
    <template slot="footer">
      <a-button icon="close" @click="handleCancel">关闭</a-button>
    </template>
    <a-spin :spinning="confirmLoading">
      <template>
        <a-descriptions :column="1" bordered size="small">
          <a-descriptions-item label="ID" style="width: 100px">
            {{ model.id }}
          </a-descriptions-item>
          <a-descriptions-item label="设备名称">
            {{ model.instanceId_dictText }}
          </a-descriptions-item>
          <a-descriptions-item label="告警配置">
            {{ model.alarmConfigId_dictText }}
          </a-descriptions-item>
          <a-descriptions-item label="告警级别">
            {{ model.alarmLevel }}
          </a-descriptions-item>
          <a-descriptions-item label="需要处理">
            {{ model.isNeedDeal }}
          </a-descriptions-item>
          <a-descriptions-item :span="2" label="触发规则">
            {{ JSON.parse(model.alarmParam).ruleExpre }}
          </a-descriptions-item>
          <a-descriptions-item :span="2" label="数据对象">
            <j-code-editor v-model="model.alarmParamMap"></j-code-editor>
          </a-descriptions-item>
          <a-descriptions-item :span="2" label="时间">
            {{ model.createTime }}
          </a-descriptions-item>
          <a-descriptions-item v-if="model.isNeedDeal" label="处理情况">
            {{ model.dealContent }}
          </a-descriptions-item>
        </a-descriptions>
      </template>
    </a-spin>
  </a-modal>
</template>

<script>
import {getAction} from '@/api/manage'
import JCodeEditor from '@comp/jeecg/JCodeEditor'

export default {
  name: 'AlarmReportModal',
  components: {JCodeEditor},
  watch: {},
  data() {
    return {
      title: '操作',
      width: 800,
      visible: false,
      model: {
        dataReport: {}
      },
      confirmLoading: false
    }
  },
  created() {
  },
  methods: {
    edit(record) {
      this.model = Object.assign(this.model, record)
      this.model.alarmParamMap = JSON.stringify(record.alarmParamMap, null, '\t')
      this.visible = true
      // this.getDataReport(record.alarmConfigId)
      this.$forceUpdate()
    },
    getDataReport(configId) {
      let scope = this
      getAction('alarm/config/queryById', { id: configId }).then(data => {
        if (data.success) {
          scope.model.dataReport = data.result
        }
      })
    },
    close() {
      this.$emit('close')
      this.visible = false
      this.$forceUpdate()
    },
    handleCancel() {
      this.close()
    },
    popupCallback(row) {
      this.form.setFieldsValue(pick(row, 'parentBy', 'code', 'name', 'modelBy', 'orgBy', 'createTime', 'description'))
    }
  }
}
</script>
